#include<bits/stdc++.h>
#define int long long
#define ll __int128
using namespace std;
const int N = 2e5+5;
const ll mod = 998244353;
int n,v[N],c[N],a[N];
namespace sub1{
	const int N = 305;
	const ll inf = 2e30;
	ll f[2][N*N];
	inline void main()
	{
		int s = 0;
		for(int i = 1;i<=n;i++) s+=c[i];
		for(int i = 0;i<=s;i++) f[0][i] = f[1][i] = -inf;
		for(int i = 0;i<=c[1];i++) f[1][i] = v[1]*(c[1]-i);
		for(int i = 2;i<=n;i++)
		{
			int now = (i&1);
			for(int j = 0;j<=s;j++) f[now][j] = -inf;
			for(int j = 0;j<=s;j++) f[now][j/a[i-1]+c[i]] = max(f[now][j/a[i-1]+c[i]],f[now^1][j]);
			for(int j = s-1;~j;j--) f[now][j] = max(f[now][j+1]+v[i],f[now][j]);
		}
		cout<<(int)(f[n&1][0]%mod);
	}
}
namespace sub2{
	inline void main()
	{
		int mx = 0,ans = 0;
		for(int i = n;i;i--)
		{
			mx = max(mx,v[i]);
			(ans+=mx*c[i])%=mod;
		}
		cout<<ans;
	}
}
namespace sub3{
	inline void main()
	{
		for(int i = 1;i<n;i++)
			if(c[i]>=a[i]&&c[i]*v[i]<=v[i+1]) c[i]-=a[i],c[i+1]++;
		int ans = 0;
		for(int i = 1;i<=n;i++)
			(ans+=c[i]*v[i])%=mod;
		cout<<ans;
	}
}
signed main()
{
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i = 1;i<=n;i++) cin>>v[i];
	int mx = 0;
	for(int i = 1;i<=n;i++) cin>>c[i],mx = max(mx,c[i]);
	bool fl = 1;
	for(int i = 1;i<n;i++) cin>>a[i],fl&=(a[i]==1);
	if(n<=300&&mx<=300) sub1::main();
	else if(fl) sub2::main();
	else sub3::main();
	return 0;
}

